package com.demo.java.OD401_450.OD416;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author bug菌
 * @Source 公众号：猿圈奇妙屋
 * @des： 【CPU 算力分配(C&D卷)】问题
 * @url： https://blog.csdn.net/weixin_43970743/article/details/146257658
 */
public class OdMain {
    public static void findMinSwap(int L1, int L2, int[] A, int[] B) {
        // 计算两组服务器的初始总算力
        int sumA = Arrays.stream(A).sum();
        int sumB = Arrays.stream(B).sum();

        // 计算差值
        int diff = (sumA - sumB) / 2;

        // 遍历A组的每个CPU，看是否有一个CPU的算力可以用于交换
        for (int aCpu : A) {
            // 计算B组中需要交换的目标算力值
            int targetCpu = aCpu - diff;
            if (Arrays.binarySearch(B, targetCpu) >= 0) {
                // 找到合适的交换组合，输出结果
                System.out.println(aCpu + " " + targetCpu);
                return;
            }
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 读入输入
        int L1 = scanner.nextInt();
        int L2 = scanner.nextInt();
        int[] A = new int[L1];
        int[] B = new int[L2];

        for (int i = 0; i < L1; i++) {
            A[i] = scanner.nextInt();
        }

        for (int i = 0; i < L2; i++) {
            B[i] = scanner.nextInt();
        }

        // 调用函数找到并输出结果
        findMinSwap(L1, L2, A, B);
    }
}
